package cn.kgc.vue.controller;

import cn.kgc.vue.common.ResponseResult;
import cn.kgc.vue.entity.User;
import cn.kgc.vue.entity.UserRole;
import cn.kgc.vue.form.UserInforForm;
import cn.kgc.vue.form.UserLsitForm;
import cn.kgc.vue.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/***
 *@title UsersController
 *@author 韩旭
 *@version 1.0.0
 *@create 2023/8/12 14:06
 **/
@RestController
@RequestMapping("user")
public class UsersController {
    @Autowired
    private UserService userService;
    ResponseResult responseResult = new ResponseResult();

    //获取用户的所有的列表
    @GetMapping("list")
    public ResponseResult list(UserLsitForm userLsitForm){
        return userService.userList(userLsitForm);
    }
    //修改用户的状态
    @GetMapping("updatestate/{id}")
    public ResponseResult updatestate(@PathVariable("id") String id,@RequestParam("state") Integer state ){
        LambdaUpdateWrapper<User> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(User::getId,id).set(User::getState,state);
        userService.update(wrapper);
        responseResult.success();
        return responseResult;
    }
    //修改用户信息
    @PostMapping("updateuser")
    public ResponseResult updateuser(@RequestBody UserInforForm userInforForm){
        return userService.updateuser(userInforForm);
    }

    //添加用户信息
    @PostMapping("adduser")
    public ResponseResult addUser(@RequestBody UserInforForm userInforForm){
        return userService.addUser(userInforForm);
    }
    //批量删除用户信息
    @DeleteMapping("delete")
    public ResponseResult delete(@RequestBody List<Integer> ids){
        return userService.delete(ids);
    }

    //获取用户的菜单
    @GetMapping("getmenulist")
    public ResponseResult getmenulist(HttpServletRequest request){
        return userService.getmenulist(request);
    }

}
